Next | Prev | Up | Top | Contents | Index
Global Code Motion
An important optimization performed by the MIPSpro compilers is called Global Code Motion (GCM). It is intended to improve the overall execution time of programs by redistributing the instructions among the basic blocks along an execution path to improve instruction parallelism and make better use of the machine resources.
Traditional global optimizers avoid moving instructions in cases which might cause them to be executed along control flow paths where they would not have been in the original program. However, GCM performs such motion, called "speculative code motion" because the instructions moved are executed based on speculation that they will actually prove useful. By default, GCM is very conservative in its speculations. Most of the options in the -GCM: group control the sorts of speculation which are to be allowed.
Valid speculative code motion must normally avoid moving operations which may cause runtime traps. As a result, turning off certain traps at runtime enables more motion. See the target environment option -TENV:X=n for general control over the exception environment.
-GCM:aggressive_speculation[=(ON|OFF)]
GCM normally tries not to move instructions to basic blocks which are already using most of the instruction execution resources available, since doing so likely extends the execution time of the block. This option minimizes that bias, which often helps floating point intensive code.
-GCM:array_speculation[=(ON|OFF)]
A form of speculation which is often very effective is called "bottom loading." It involves moving instructions from the top of a loop body to both the block before the loop (for the first iteration) and to the end of the loop body (which executes them at the end of one iteration so that they are ready early for the next iteration). Doing this, however, means that the instructions are executed one or more extra times in the last iteration(s) of the loop. If the instructions moved are loading elements of an array, this may cause extra accesses beyond the end of the array. This option enables such accesses a small distance beyond the endof the array. The compiler attempts to pad arrays to guarantee that such accesses won't cause memory faults, but it may not always be able to do so, so this option must be used with care.
-GCM:pointer_speculation[=(ON|OFF)]
This option allows speculative motion of loads of two kinds, both involving pointer usage. The first is to allow motion of loads through pointers which may be NULL. In order to prevent this from causing memory faults, the compiler causes page zero of the address space to be mapped at runtime. Since this may prevent some truly invalid references from causing faults, this option should be avoided during debugging.
The second form involves moving a reference like *(p+n), for a small integer n, to a block which already contains a reference to *p. The assumption involved is that if p is a valid address, p+n is too.
Consider an example:
...
if ( p->next != NULL ) {
sum += p->next->val;
}
...
If this option is set, the load of p->next->val can be moved before the if (it is through a potentially NULL pointer).
-GCM:static_load_speculation[=(ON|OFF)]
Allow the speculative motion of loads from static data areas.Since such areas are known to be allocated, such motion cannot cause new faults except page faults or cache misses. As a result, it is generally safe, although it may hurt performance if it causes unnecessary page faults or cache misses.
-GCM:prepass[=(ON|OFF)]
-GCM:postpass[=(ON|OFF)]
GCM is implemented in two passes, one before instruction scheduling and register allocation, and one after, currently enabled at optimization level 2 (-O2) and above. These options allow either or both of the passes to be enabled or disabled. The two passes are complementary in effect, often improving code more in combination than the sum of their individual improvements, so enabling just one is not recommended.
Next | Prev | Up | Top | Contents | Index